package com.iscas.dataaggregation.strategy;

import java.util.Map;

public class HttpChaosStrategy implements ChaosFaultTypeStrategy {

    @Override
    public String getFaultType(Map<String, Object> data) {
        String chaosType = (String) data.get("chaosType");
        Map<String, Object> chaosData = (Map<String, Object>) data.get(chaosType);
        System.out.println("data: " + data);

        // 判断是 Request 还是 Response
        String target = (String) chaosData.get("target");
        target = (target != null) ? target : "";
        // 匹配字段
        String faultKey = "";
        if (chaosData.containsKey("abort")) {
            faultKey = "abort";
        } else if (chaosData.containsKey("delay")) {
            faultKey = "delay";
        } else if (chaosData.containsKey("replace")) {
            faultKey = "replace";
        } else if (chaosData.containsKey("patch")) {
            faultKey = "patch";
        }
        System.out.println("faultKey: " + faultKey);

        // 拼接结果
        return chaosType + " " + target + " " + faultKey;
    }
}
